import {Http} from "../Http";

export class ServiceApi {
    static getAppList(body:any) {
        return Http.post("/manager/rest/app/search", body || {});
    }

    static lastBuild(appId:any) {
        return Http.get("/manager/rest/build/last", {appId: appId})
    }

    static createApp(data:any) {
        return Http.post("/manager/rest/app/create", [data])
    }

    /**
     * 执行构建，返回一个长连接
     * @param data
     * @param callback
     * @param endCallback
     */
    static executeBuild(data?:any, callback?: Function, endCallback?: Function): Promise<any> {
        return Http.post("/manager/rest/build/execute", {
            "appId": "5eef71847b3e6f1f3822daea",
            "envId": "5eef71d67b3e6f1f3822daeb",
            "clusterId": "5ef0be3d062f650f08d135a1"
        });
    }

    static logWs(onmessage: ((this: WebSocket, ev: MessageEvent) => any)) {
        return Http.websocket("ws://localhost:8080/logs", {
            onmessage: onmessage
        })
    }

    static clusterList(){
        return Http.get('/manager/rest/cluster/list', {});
    }

    static clusterInfo(clusterId: string) {
        return Http.get('/manager/rest/cluster/info?clusterId=' + clusterId, {});
    }

    static images(clusterId: string) {
        return Http.get('/manager/rest/cluster/images?clusterId=' + clusterId, {});
    }

    static containers(clusterId: string) {
        return Http.get('/manager/rest/cluster/containers?clusterId=' + clusterId, {});
    }

    static deleteApp(appIds: string[]) {
        return Http.delete('/manager/rest/app/delete', appIds);
    }
}
